package com.cxrj.zhsq.serviceManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.serviceManage.entity.PropertyServiceEntity;
import com.cxrj.zhsq.serviceManage.entity.PropertyServiceType;
import com.cxrj.zhsq.serviceManage.service.PropertyService;

@RestController
public class PropertyServiceController {

	@Resource
	private PropertyService propertyService;

	/**
	 * 分页查询服务类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyServiceTypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectPropertyServiceTypes(HttpServletRequest request, HttpServletResponse response) {
		return propertyService.seleteServiceTypePage(request, response);
	}

	/**
	 * 分页查询服务
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyServices", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectPropertyServices(HttpServletRequest request, HttpServletResponse response) {
		return propertyService.seleteServicePage(request, response);
	}

	/**
	 * 添加服务类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyServiceType", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyServiceType(PropertyServiceType propertyServiceType, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyServiceType.setCommunityId(request.getSession().getAttribute("communityId").toString());
			resultMap = propertyService.insertServiceType(propertyServiceType);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 添加服务
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyService", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyService(PropertyServiceEntity propertyServiceEntity, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyServiceEntity.setCommunityId(request.getSession().getAttribute("communityId").toString());
			resultMap = propertyService.insertService(propertyServiceEntity);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改服务类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyServiceType", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyServiceType(PropertyServiceType propertyServiceType, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = propertyService.updateServiceType(propertyServiceType);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改服务
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyService", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyService(PropertyServiceEntity propertyServiceEntity, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = propertyService.updateService(propertyServiceEntity);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 根据id查询服务类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyServiceTypeById", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyServiceTypeById(String id, HttpServletRequest request) {
		return propertyService.seleteServiceTypeById(id);
	}

	/**
	 * 根据id查询服务
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyServiceById", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyServiceById(String id, HttpServletRequest request) {
		return propertyService.seleteServiceById(id);
	}
	
	/**
	 * 查询使用服务类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyServiceTypeByAll", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyServiceTypeByAll(HttpServletRequest request) {
		return propertyService.selectServiceTypeByAll();
	}
}
